package com.xinzhitong.www.mapper;

import com.xinzhitong.www.pojo.Trade;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

/**
 * 购买表相关操作
 *
 * @author 徐鑫
 */
@Repository
public interface BuyMapper {

    @Insert("insert into buy(out_trade_no, total_amount, username, good_id, type) " +
            "values(#{outTradeNo}, #{totalAmount}, #{username}, #{goodId}, #{goodType})")
    Integer insertTrade(Trade trade);

    @Insert("insert into ${table} values(#{username}, #{id})")
    void insertUserHasSomething(
            @Param("table") String table,
            @Param("username") String username,
            @Param("id") Integer id
    );

    @Select("select * from buy where username=#{username} and good_id=#{goodId}")
    Trade selectTradeByUsernameAndGoodId(@Param("username") String username, @Param("goodId") Integer goodId);

}
